#!/usr/bin/env python3

import sys


def parse_conf(_f, upper_level, num):
    _ret = 0
    cycle = 0
    last_idx = 0
    with open(_f, 'r') as _fd:
        for _l in _fd.readlines():
            _ll = _l.strip()

            # skip null lines
            if not _ll:
                continue

            # skip comment lines
            if _ll.find("#") == 0:
                continue

            # get kv
            eidx = _ll.find("(")
            if eidx == -1:
                print("WARNNING: not = find in " + _ll);
                continue
            level = upper_level
            tmpidx = _ll.find("+-")
            if tmpidx == -1:
                tmpidx = _ll.find("\-")
                if tmpidx != -1 and eidx != -1:
                    lastidx = tmpidx
                    level = tmpidx
                    key = _ll[0:tmpidx].strip()
                    val = _ll[0:].strip()
                    count = 0;
                    for i in key:
                        if i == "|":
                            count += 1
                    level = count
            else:
                if last_idx == tmpidx:
                    last_idx = 0
                level = tmpidx
                key = _ll[0:tmpidx].strip()
                val = _ll[0:].strip()
                count = 0;
                for i in key:
                    if i == "|":
                        count += 1
                level = count
                if last_idx != 0:
                    level += 1
            if level >= int(upper_level) + 2:
                continue
            if level <= int(upper_level):
                break

            cycle += 1
            if cycle < int(num):
                continue
            print(val)
            break

    return _ret

if __name__ == "__main__":
    _f1 = sys.argv[1];
    level = sys.argv[2];
    num = sys.argv[3];

    _kv1 = parse_conf(_f1, level, num);
